<%@ page import="org.xilin.Family"%>
<%@ page import="org.xilin.Course"%>
<%@ page import="org.xilin.Student"%>
<%@ page import="org.xilin.Semester"%>
<g:setProvider library="jquery"/>

<x:message message="${flash.message}"/>

<div class="bar">
  <span class="left">Class Registration</span>
  <span class="right semester">
    <b>Semester: </b><x:semesterSelection semesterId="${session.activeSemester?.id}"/>
      &nbsp;&nbsp;
    <b> Student: </b><x:studentSelection studentId="${params.studentId}"/>
  </span>
</div>
<div>
  <table class="tablesorter">
    <caption>Registered Classes for Student ${studentInstance}</caption>
     <thead>
    <tr>
      <th>Course</th><th>Start Time</th><th>End Time</th><th>Instructor</th><th>Book</th><th>Buy Book</th><th/>
    </tr>
     </thead>
    <g:each in="${studentInstance?.classes}" status="i" var="classInstance">
      <tr>
        <td>${classInstance.course?.name}</td>
        <td>${classInstance.course?.startTime}</td>
        <td>${classInstance.course?.endTime}</td>
        <td>${classInstance.course?.teacher}</td>
        <g:if test="${classInstance.course?.book}">
        <td class="show"><a href="#" title="Book Detail" rel="${request.contextPath}/book/show/${classInstance.course?.book?.id}">${classInstance.course?.book}</a></td>
        <td><g:checkBox name="${classInstance?.id}" value="${classInstance.bookIncluded?true:false}" onclick="bookOption(this.name, this.value, ${params.studentId});" /></td>
        </g:if><g:else>
          <td/><td/>
        </g:else>
        <td><span class="smallbtn right"><g:remoteLink action="dropCourse" update=".content" params="'courseId=${classInstance.course.id}&studentId=${params.studentId}'">Drop Class</g:remoteLink></span></td>
      </tr>
    </g:each>
  </table>
</div>

<x:pager/>
<table id="courseTable" class="tablesorter">
    <caption>Classes Open for Semester ${session.activeSemester}</caption>
    <thead>
        <tr>
            <th>${message(code: 'course.name.label', default: 'Name')}</th>
            <th>${message(code: 'course.grade.label', default: 'Grade')}</th>
            <th>${message(code: 'course.price.label', default: 'Price')}</th>
            <th>${message(code: 'course.startTime.label', default: 'Start Time')}</th>
            <th>${message(code: 'course.endTime.label', default: 'End Time')}</th>
            <th>${message(code: 'course.teacher.label', default: 'Teacher')}</th>
            <th>${message(code: 'course.book.label', default: 'Book')}</th>
            <th/>
            <th style="display:none">${message(code: 'course.status.label', default: 'Status')}</th>
        </tr>
    </thead>
    <tbody>
    <g:each in="${courseInstanceList}" status="i" var="courseInstance">
        <tr>
            <td class="show"><a href="#" title="Course Detail" rel="${request.contextPath}/course/show/${courseInstance.id}">${fieldValue(bean: courseInstance, field: "name")}</a></td>
            <td>${fieldValue(bean: courseInstance, field: "grade")}</td>
            <td>${fieldValue(bean: courseInstance, field: "price")}</td>
            <td>${fieldValue(bean: courseInstance, field: "startTime")}</td>
            <td>${fieldValue(bean: courseInstance, field: "endTime")}</td>
            <td>${fieldValue(bean: courseInstance, field: "teacher")}</td>
            <td class="show"><a href="#" title="Book Detail" rel="${request.contextPath}/book/show/${courseInstance.book?.id}">${fieldValue(bean: courseInstance, field: "book")}</a></td>
        <g:if test="${courseInstance.regCapacity < courseInstance.capacity}">
            <td><span class="smallbtn right">
            <g:remoteLink action="addCourse" update=".content" params="'courseId=${courseInstance.id}&studentId=${params.studentId}'">Add Class</g:remoteLink>
            </span></td>
        </g:if>
        <g:else>
          <td align="right">Class Full</td>
        </g:else>
            <td style="display:none">${fieldValue(bean: courseInstance, field: "status")}</td>        
        </tr>
    </g:each>
    </tbody>
</table>

<script type="text/javascript">
  $(function(){
      setupAdminList({controller:'classRegister', action:'makeSelection'});
  });
</script>

